package Base.基本的三种创建方法;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author 陈鹏
 */
public class CallableTest2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Mythread3 mythread3=new Mythread3();
        FutureTask<Object>ft1=new FutureTask<Object>(mythread3);
        Thread thread1=new Thread(ft1,"thread1");
        thread1.start();
        FutureTask<Object>ft2=new FutureTask<Object>(mythread3);
        Thread thread2=new Thread(ft2,"thread2");
        thread2.start();
        System.out.println(ft1.get());
        System.out.println(ft2.get());
    }
}

class Mythread3 implements Callable{

    @Override
    public Object call() throws Exception {
        int i=0;
        while (i++<5){
            System.out.println(Thread.currentThread().getName()+"call在运行");
        }
        return i;
    }
}
